#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int Add(int x, int y)
{
	return x + y;
}
int Sub(int x, int y)
{
	return x - y;
}
int Mul(int x, int y)
{
	return x * y;
}
int Div(int x, int y)
{
	return x / y;
}
void menu()
{
	printf("*************************\n");
	printf("  1:add           2:sub  \n");
	printf("  3:mul           4:div  \n");
	printf("  0:exit                 \n");
	printf("*************************\n");
	printf("请选择：" );
}
int main()
{
	int num1 = 0;
	int (*p[5])(int, int) = { NULL,Add,Sub,Mul,Div };//通过下标访问其他函数：转移表（转移表以索引快速调用函数）
	do {
		int n1 = 0, n2 = 0;
		menu();
		scanf("%d", &num1);
		if (num1 == 0)
			break;
		else if ((num1 <= 4) && (num1 >= 0))
		{
			printf("请输入两个整数：\n");
			scanf("%d%d", &n1, &n2);
			int result = p[num1](n1, n2);
			printf("result=%d\n", result);
		}
		else
			printf("输入有误！\n");
	} while (num1);
	return 0;
}